package org.cybzacg.convert.enums;

import lombok.Getter;

/**
 * 转换类型枚举
 * 定义所有支持的转换类型
 *
 * @author cybzacg.blog
 * @version 3.0
 * @since 3.0
 */
@Getter
public enum ConversionType {

    // 基本类型
    STRING("String", "字符串类型", 1),
    BOOLEAN("Boolean", "布尔类型", 2),
    CHARACTER("Character", "字符类型", 3),

    // 数值类型
    BYTE("Byte", "字节类型", 10),
    SHORT("Short", "短整型", 11),
    INTEGER("Integer", "整型", 12),
    LONG("Long", "长整型", 13),
    FLOAT("Float", "单精度浮点型", 14),
    DOUBLE("Double", "双精度浮点型", 15),
    BIG_DECIMAL("BigDecimal", "大数类型", 16),
    BIG_INTEGER("BigInteger", "大整数类型", 17),
    NUMBER("Number", "数字类型", 18),

    // 日期时间类型
    DATE("Date", "日期类型", 20),
    LOCAL_DATE("LocalDate", "本地日期", 21),
    LOCAL_TIME("LocalTime", "本地时间", 22),
    LOCAL_DATE_TIME("LocalDateTime", "本地日期时间", 23),
    ZONED_DATE_TIME("ZonedDateTime", "时区日期时间", 24),
    INSTANT("Instant", "时间戳", 25),
    YEAR("Year", "年份", 26),
    YEAR_MONTH("YearMonth", "年月", 27),
    PERIOD("Period", "时间段", 28),
    DURATION("Duration", "持续时间", 29),

    // 集合类型
    COLLECTION("Collection", "集合接口", 30),
    LIST("List", "列表", 31),
    SET("Set", "集合", 32),
    MAP("Map", "映射", 33),
    QUEUE("Queue", "队列", 34),
    DEQUE("Deque", "双端队列", 35),

    // 数组类型
    ARRAY("Array", "数组", 40),

    // 对象类型
    OBJECT("Object", "对象类型", 50),
    CUSTOM("Custom", "自定义类型", 51),
    ENUM("Enum", "枚举类型", 52);

    private final String code;
    private final String description;
    private final int order;

    ConversionType(String code, String description, int order) {
        this.code = code;
        this.description = description;
        this.order = order;
    }

    /**
     * 根据类型名称获取转换类型
     *
     * @param typeName 类型名称
     * @return 转换类型
     */
    public static ConversionType fromTypeName(String typeName) {
        if (typeName == null) {
            return null;
        }

        for (ConversionType type : values()) {
            if (type.name().equalsIgnoreCase(typeName) ||
                type.getCode().equalsIgnoreCase(typeName)) {
                return type;
            }
        }

        // 处理基本类型
        return switch (typeName.toLowerCase()) {
            case "int" -> INTEGER;
            case "char" -> CHARACTER;
            case "boolean" -> BOOLEAN;
            case "long" -> LONG;
            case "float" -> FLOAT;
            case "double" -> DOUBLE;
            case "short" -> SHORT;
            case "byte" -> BYTE;
            case "big_decimal" -> BIG_DECIMAL;
            case "big_integer" -> BIG_INTEGER;
            case "number" -> NUMBER;
            default -> CUSTOM;
        };
    }

    /**
     * 检查是否为基本类型
     *
     * @return 是否为基本类型
     */
    public boolean isBasicType() {
        return order >= 1 && order <= 3;
    }

    /**
     * 检查是否为数值类型
     *
     * @return 是否为数值类型
     */
    public boolean isNumberType() {
        return order >= 10 && order <= 17;
    }

    /**
     * 检查是否为日期时间类型
     *
     * @return 是否为日期时间类型
     */
    public boolean isDateTimeType() {
        return order >= 20 && order <= 29;
    }

    /**
     * 检查是否为集合类型
     *
     * @return 是否为集合类型
     */
    public boolean isCollectionType() {
        return order >= 30 && order <= 35;
    }

    /**
     * 检查是否为对象类型
     *
     * @return 是否为对象类型
     */
    public boolean isObjectType() {
        return order >= 50;
    }

    @Override
    public String toString() {
        return String.format("%s(%s) - %s", code, name(), description);
    }
}
